'use strict';
const db = uniCloud.database();
const dbCmd = db.command;
const $ = dbCmd.aggregate;
const uniID = require('uni-id')
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const uniIDIns = uniID.createInstance({
	  context
	})
	event.watcherId = '';
	let payload={};
	 //console.log(event,'eeeeeeeeeeeeeeee')
	 if(event.uniIdToken){
		 payload =await uniIDIns.checkToken(event.uniIdToken)
		  //console.log(payload,'pppppppppppppppppppppp')
		 if (payload.code && payload.code > 0) {
		 	return payload
		 }
		 event.watcherId=payload.uid;
	 }
	 const res =  db.collection('local').add(event)
	//返回数据给客户端
	return res
};
